home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / sunprom / proc.h.strip < prev    next >
Text File  |  1989-06-10  |  19KB  |  606 lines

  1. /*
  2.  * proc.h --
  3.  *
  4.  *    External declarations of data structures and routines 
  5.  *    for managing processes.
  6.  *
  7.  * Copyright 1986, 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  *
  17.  * rcsid $Header: /sprite/src/kernel/proc/RCS/proc.h,v 8.6 89/05/28 01:18:47 rab Exp $ SPRITE (Berkeley)
  18.  */
  19.  
  20. #ifndef _PROC
  21. #define _PROC
  22.  
  23. #include "user/proc.h"
  24. #include "sync.h"
  25. #include "list.h"
  26. #include "mach.h"
  27.  
  28. /*
  29.  * Constants for Proc_Exec().  
  30.  *
  31.  * PROC_MAX_EXEC_ARG_LENGTH    The maximum length of any argument that is
  32.  *                passed to exec.
  33.  * PROC_MAX_EXEC_ARGS        The maximum number of arguments that can be
  34.  *                passed to an exec'd process.
  35.  */
  36.  
  37. #define    PROC_MAX_EXEC_ARG_LENGTH    1024
  38. #define    PROC_MAX_EXEC_ARGS        512
  39.  
  40. /*
  41.  * Masks to extract the proc table index and the generation number from
  42.  * a process id.  Process IDs need to be unique across reuses of the same
  43.  * procTable slot, and they need to be unique from host to host.
  44.  */
  45.  
  46. /*
  47.  * PROC_INDEX_MASK is defined in user/proc.h.
  48.  * #define    PROC_INDEX_MASK        0x000000FF
  49.  */
  50. #define    PROC_ID_NUM_MASK    0x0000FF00
  51. #define PROC_ID_NUM_SHIFT    8
  52. #define    PROC_GEN_NUM_MASK    0x000F0000
  53. #define PROC_GEN_NUM_SHIFT    16
  54.  
  55.  
  56. /*
  57.  * Number of locks that can be pushed on the lock stack for a process. The
  58.  * stack is used in the sync module to determine the locking structure of the
  59.  * system.
  60.  */
  61. #define PROC_LOCKSTACK_SIZE 10
  62.  
  63.  
  64. /* DATA STRUCTURES */
  65.  
  66. /*
  67.  * Structure passed to the function called by Proc_CallFunc.
  68.  */
  69. typedef struct {
  70.     unsigned int    interval;    /* Set by func to cause it to be 
  71.                      * rescheduled. */
  72.     ClientData        clientData;    /* Data given to Proc_CallFunc*(). */
  73.     ClientData        token;        /* Unique token to identify this call.*/
  74. } Proc_CallInfo;
  75.  
  76. /*
  77.  * Structure to describe an environment.
  78.  */
  79.  
  80. typedef struct {
  81.     int            refCount;    /* Number of processes using this 
  82.                        environment. */
  83.     int            size;        /* Number of elements in environment. */
  84.     struct ProcEnvironVar *varArray;    /* The environment itself. */
  85. } Proc_EnvironInfo;
  86.  
  87. /*
  88.  * >>> Process state flags have been moved to user/proc.h <<<
  89.  */
  90.  
  91. /*
  92.  *  Proc_PCBLinks is used to link the PCB entry into various doubly-linked
  93.  *  lists. For example, processes waiting on an event are linked togther.
  94.  */
  95.  
  96. typedef struct {
  97.     List_Links links;            /* Linked list for the hash chain. */
  98.     struct Proc_ControlBlock *procPtr;    /* Back pointer to this structure. */
  99. } Proc_PCBLink;
  100.  
  101.  
  102. /*
  103.  * Proc_Time is used to represent time such that it can be understood
  104.  * by users through Proc_GetPCBInfo in a machine independent format and
  105.  * by the kernel in a machine dependent ticks format.  Thus all users of
  106.  * Proc_Time in the kernel should always use the ticks field and user
  107.  * programs that call Proc_GetPCBInfo should use the time field.
  108.  */
  109. typedef union {
  110.     Timer_Ticks    ticks;    /* The kernel's notion of time. */
  111.     Time    time;    /* The user's notion of time. */
  112. } Proc_Time;
  113.  
  114. typedef struct {
  115.     int        type;        /* type of lock */
  116.     Address    lockPtr;    /* Ptr to lock */
  117. } Proc_LockStackElement;
  118.  
  119. /*
  120.  *  The Proc_ControlBlock structure:
  121.  *   It contains information to manage the process such as virtual 
  122.  *   memory usage, cpu usage, scheduling info, process state, 
  123.  *   which processor the process is executing on, etc.
  124.  */
  125.  
  126. typedef struct Proc_ControlBlock {
  127.     List_Links    links;        /* Used to link processes together. */
  128.  
  129.     int        processor;    /* Processor number the process is running on
  130.                  * or wants to run on if the processor is
  131.                  * available.  */
  132.  
  133.     Proc_State    state;        /* Describes a process's current running state.
  134.                  * >>> See Proc_State definitions above. */ 
  135.  
  136.     int        genFlags;    /* Flags to describe a processes overall state.
  137.                  * >>> See definitions below */ 
  138.     int        syncFlags;    /* Flags used by the sync module. */
  139.     int        schedFlags;    /* Flags used by the sched module. */
  140.     int        exitFlags;    /* Flags used by the exit-detach-
  141.                   * wait monitor. */
  142.  
  143.     List_Links        childListHdr;    /* Header for list of children. */
  144.     List_Links        *childList;    /* Pointer to header of list. */
  145.     Proc_PCBLink    siblingElement;    /* Element in list of sibling 
  146.                      * processes. */
  147.     Proc_PCBLink    familyElement;    /* Element in a list of family
  148.                        members. */
  149.  
  150.     /*
  151.      *-----------------------------------------------------------------
  152.      *
  153.      *   Various Process Identifiers.
  154.      *    
  155.      *    Note that the user and effectiveUser ID are kept here because
  156.      *    they are used for permission checking in various places.  There
  157.      *    is also a list of group IDs which is kept in the filesystem state.
  158.      *
  159.      *-----------------------------------------------------------------
  160.      */
  161.  
  162.     Proc_PID    processID;        /* Actual process ID of this
  163.                      * process (for migrated processes
  164.                      * this is different than the PID
  165.                      * that the user sees). */
  166.     Proc_PID    parentID;        /* The process ID of the parent 
  167.                      * of this process. */
  168.     int        familyID;        /* The id of the process family that 
  169.                      * this process belongs to. */
  170.     int        userID;            /* The user id is used to check access
  171.                      * rights to files and check ability
  172.                      * to signal other processes. */
  173.     int        effectiveUserID;    /* The effective user id is used
  174.                      * for setuid access. */
  175.  
  176.     /*
  177.      *-----------------------------------------------------------------
  178.      *
  179.      *    Synchronization fields.
  180.      *
  181.      * Synchronization state includes an event the process is waiting on.
  182.      * PCB's are linked into a hash chain keyed on this event.
  183.      *
  184.      *-----------------------------------------------------------------
  185.      */
  186.  
  187.     int         event;         /* Event # the process is waiting for. */
  188.     Proc_PCBLink eventHashChain; /* Hash chain this PCB is linked to */
  189.  
  190.     /*
  191.      * Monitor conditions for locking this PCB entry.
  192.      */
  193.  
  194.     Sync_Condition    waitCondition;
  195.     Sync_Condition    lockedCondition;
  196.  
  197.     /*
  198.      * Fields for remote waiting.  A token is kept to guard against the
  199.      * race between the wakeup message and the process's decision to sleep.
  200.      */
  201.  
  202.     int            waitToken;
  203.  
  204.     /*
  205.      *-----------------------------------------------------------------
  206.      *
  207.      *    Scheduling fields.
  208.      *
  209.      *-----------------------------------------------------------------
  210.      */
  211.  
  212.  
  213.     int      billingRate;    /* Modifies the scheduler's calculation of
  214.                  * the processes priority.  */
  215.     unsigned int recentUsage;    /* Amount of CPU time used recently */
  216.     unsigned int weightedUsage;    /* Smoothed avg. of CPU usage, weighted by
  217.                  * billing rate. */
  218.     unsigned int unweightedUsage; /* Smoothed avg. of CPU usage, not weighted by
  219.                    * billing rate. */
  220.  
  221.     /*
  222.      *-----------------------------------------------------------------
  223.      *
  224.      *    Accounting and Resource Usage fields.
  225.      *
  226.      *-----------------------------------------------------------------
  227.      */
  228.  
  229.     Proc_Time kernelCpuUsage;    /* How much time has been spent in kernel mode*/
  230.     Proc_Time userCpuUsage;    /* How much time has been spent in user mode. */
  231.  
  232.     Proc_Time childKernelCpuUsage;    /* Sum of time spent in kernel mode for 
  233.                       * all terminated children. */
  234.     Proc_Time childUserCpuUsage;    /* Sum of time spent in user mode for
  235.                       * all terminated children. */
  236.     int     numQuantumEnds;        /* number of times the process was 
  237.                       * context switched due to a quantum 
  238.                      * end. */
  239.     int        numWaitEvents;        /* number of times the process was
  240.                      * context switched due to its waiting 
  241.                      * for an event. */
  242.     unsigned int schedQuantumTicks;    /* Number of clock ticks until this 
  243.                      * process is due to be switched out. */
  244.  
  245.  
  246.     /*
  247.      *-----------------------------------------------------------------
  248.      *
  249.      *   Machine-Dependent fields.
  250.      *
  251.      *    General processor registers, stack information.
  252.      *
  253.      *-----------------------------------------------------------------
  254.      */ 
  255.     struct    Mach_State    *machStatePtr;
  256.  
  257.  
  258.     /*
  259.      *-----------------------------------------------------------------
  260.      *
  261.      *   Virtual Memory fields.
  262.      *
  263.      *-----------------------------------------------------------------
  264.      */
  265.     struct    Vm_ProcInfo    *vmPtr;
  266.  
  267.     /*
  268.      *-----------------------------------------------------------------
  269.      *
  270.      *   I/O and File System fields.
  271.      *
  272.      *-----------------------------------------------------------------
  273.      */
  274.  
  275.     struct Fs_ProcessState    *fsPtr;
  276.  
  277.     /*
  278.      *-----------------------------------------------------------------
  279.      *
  280.      *   Termination Reason, Status and Status Subcode Information.
  281.      *
  282.      *-----------------------------------------------------------------
  283.      */
  284.  
  285.     int    termReason;        /* Reason why process has died or
  286.                  * it has been detached. */
  287.                 /* >>> See definitions in procUser.h */
  288.     int    termStatus;        /* Exit/detach status or signal number
  289.                  * that caused the process to die. */
  290.                 /* >>> See definitions in procUser.h */
  291.     int    termCode;        /* The code for the signal. */
  292.                 /* >>> See definitions in procUser.h */
  293.  
  294.  
  295.     /*
  296.      *-----------------------------------------------------------------
  297.      *
  298.      *    Signals
  299.      *
  300.      *-----------------------------------------------------------------
  301.      */
  302.  
  303.     int        sigHoldMask;        /* Mask of signals to be held. */
  304.     int        sigPendingMask;        /* Mask of pending signals. */
  305.                         /* Array of the different types
  306.                        of actions for signals. */
  307.     int        sigActions[SIG_NUM_SIGNALS];
  308.                         /* Array of signal hold masks for 
  309.                        signal handlers. */
  310.     int        sigMasks[SIG_NUM_SIGNALS];
  311.                     /* Array of signal handlers for 
  312.                        signals. */
  313.     int        sigCodes[SIG_NUM_SIGNALS];
  314.     int        sigFlags;        /* Flags to indicate the signal 
  315.                        state. */
  316.     int        oldSigHoldMask;        /* Mask of held signals when a
  317.                        Sig_Pause call starts. */
  318.  
  319.     /*
  320.      * Info for interval timers. The timer info is not put directly in
  321.      * this struct so additional timers can be added without extending
  322.      * the struct. This information is used to deliver the SIG_TIMER signal
  323.      * to the process.
  324.      */
  325.     struct ProcIntTimerInfo    *timerArray;
  326.  
  327.     /*
  328.      *---------------------------------------------------------------------
  329.      *
  330.      * Data for process migration.
  331.      *
  332.      *---------------------------------------------------------------------
  333.      */
  334.     int            peerHostID;    /* If on home node, ID of remote node.
  335.                      * If on remote node, ID of home node.
  336.                      * If not migrated, undefined. */
  337.     Proc_PID        peerProcessID;     /* If on remote note, process ID on
  338.                      * home node, and vice-versa. */
  339.     struct Proc_ControlBlock
  340.                  *rpcClientProcess;    /* procPtr for migrated process
  341.                      * performing system call, if
  342.                      * applicable. */
  343.  
  344.     /*
  345.      *---------------------------------------------------------------------
  346.      *
  347.      *  Miscellaneous items:
  348.      *
  349.      *---------------------------------------------------------------------
  350.      */
  351.  
  352.     /*
  353.      * Info that describes the process's environment variable table.
  354.      */
  355.     Proc_EnvironInfo    *environPtr;
  356.  
  357.     /*
  358.      * Arguments for the process, taken from Proc_Exec.
  359.      */
  360.     char    *argString;
  361.  
  362.     /*
  363.      * Stack of locks that process has grabbed.
  364.      */
  365.      Proc_LockStackElement    lockStack[PROC_LOCKSTACK_SIZE];
  366.      int            lockStackSize;
  367.  
  368.     /*
  369.      * Used to speed up basic kernel-call processing.  These two fields
  370.      * must be next to each other in the table, and in the order below.
  371.      * If you change this, you'll have to change the assembler code that
  372.      * takes kernel-call traps.
  373.      */
  374.  
  375.     ReturnStatus (**kcallTable)();    /* Pointer to array of addresses,
  376.                      * which are procedures to handle
  377.                      * the various kernel calls.  Points
  378.                      * to a different place for migrated
  379.                      * processes than for processes running
  380.                      * at home. */
  381.     int specialHandling;        /* If non-zero, means the process
  382.                      * requires special (slower) handling
  383.                      * (deliver signal, switch contexts,
  384.                      * ect.) on return from the next kernel
  385.                      * call. */
  386.  
  387.     /*
  388.      *---------------------------------------------------------------------
  389.      *
  390.      *  User level profiling information
  391.      *
  392.      *---------------------------------------------------------------------
  393.      */
  394.  
  395.      short *Prof_Buffer;    /* Pointer to an array of profiling information
  396.                              * in the process's address space. */
  397.      int Prof_BufferSize;   /* The size of Prof_Buffer. */
  398.      int Prof_Offset;       /* Value subtracted from the program counter */
  399.      int Prof_Scale;        /* 16 bit fixed point fraction.  Scales the PC
  400.                              * to fit in the Prof_Buffer */
  401.      int Prof_PC;           /* Program counter recorded during the last
  402.                              * timer tick. */
  403.  
  404. } Proc_ControlBlock;
  405.  
  406. /*
  407.  * Exit-detach-wait monitor flags:
  408.  *
  409.  *  PROC_DETACHED        - This process is detached from its parent.
  410.  *                  When this process exits, it won't go on the
  411.  *                  exiting processes list.
  412.  *  PROC_WAITED_ON        - This process is detached and the parent has 
  413.  *                  already done a Proc_Wait on it.
  414.  *  PROC_SUSPEND_STATUS        - The process went into the suspended state
  415.  *                  and it hasn't been waited on yet.
  416.  *  PROC_RESUME_STATUS        - The process was resumed and it hasn't been 
  417.  *                  waited on yet.
  418.  *  PROC_STATUSES        - The union of the two above statuses.
  419.  */
  420.  
  421. #define PROC_DETACHED        0x01
  422. #define PROC_WAITED_ON        0x02
  423. #define    PROC_SUSPEND_STATUS    0x04
  424. #define    PROC_RESUME_STATUS    0x08
  425. #define    PROC_STATUSES        (PROC_SUSPEND_STATUS | PROC_RESUME_STATUS)
  426.  
  427.  
  428.  
  429.  
  430.  
  431. /*
  432.  *  proc_RunningProcesses points to an array of pointers to
  433.  *  Proc_ControlBlock structures of processes currently running on each
  434.  *  CPU.  It is initialized by Proc_Init at boot time to the appropriate
  435.  *  size, which depends on the workstation configuration.
  436.  */
  437.  
  438. extern Proc_ControlBlock  **proc_RunningProcesses;
  439.  
  440.  
  441. /*
  442.  *  proc_PCBTable is the array of all valid PCB's in the system.
  443.  *  It is initialized by Proc_Init at boot time to the appropriate size,
  444.  *  which depends on the workstation configuration.
  445.  */
  446.  
  447. extern Proc_ControlBlock **proc_PCBTable;
  448.  
  449.  
  450. /*
  451.  *   Keep track of the maximum number of processes at any given time.
  452.  */
  453.  
  454. extern int proc_MaxNumProcesses;
  455.  
  456. /*
  457.  * set to TRUE to disallow all migrations to this machine.
  458.  */
  459. extern Boolean proc_RefuseMigrations;
  460.  
  461. /*
  462.  *  Macros to manipulate process IDs.
  463.  */
  464.  
  465. #define Proc_ComparePIDs(p1, p2) (p1 == p2)
  466.  
  467. #define Proc_GetPCB(pid) (proc_PCBTable[pid & PROC_INDEX_MASK])
  468.  
  469. #define Proc_ValidatePID(pid) \
  470.     (((pid & PROC_INDEX_MASK) < proc_MaxNumProcesses) && \
  471.      ((pid == proc_PCBTable[pid & PROC_INDEX_MASK]->processID)))
  472.  
  473. #define PROC_GET_VALID_PCB(pid, procPtr) \
  474.     if ((pid & PROC_INDEX_MASK) >= proc_MaxNumProcesses) { \
  475.     procPtr = (Proc_ControlBlock *) NIL; \
  476.     } else { \
  477.     procPtr = proc_PCBTable[pid & PROC_INDEX_MASK]; \
  478.     if (pid != procPtr->processID) { \
  479.         procPtr = (Proc_ControlBlock *) NIL; \
  480.     } \
  481.     }
  482.  
  483. #define    Proc_GetHostID(pid) ((pid & PROC_ID_NUM_MASK) >> PROC_ID_NUM_SHIFT)
  484.  
  485. /*
  486.  * Macros to determine and set the "actual" currently running process.
  487.  */
  488.  
  489. #define    Proc_GetActualProc() \
  490.     proc_RunningProcesses[Mach_GetProcessorNumber()]
  491. #define Proc_SetActualProc(processPtr) \
  492.     proc_RunningProcesses[Mach_GetProcessorNumber()] = processPtr
  493.  
  494. #define Proc_GetCurrentProc() Proc_GetActualProc()
  495. #define Proc_SetCurrentProc(processPtr)    Proc_SetActualProc(processPtr)
  496.  
  497. /*
  498.  * Various routines use Proc_IsMigratedProcess to decide whether the
  499.  * effective process is different from the actual process (i.e.,
  500.  * migrated).  This macro bypasses the procedure call, since
  501.  * proc_RunningProcesses[processor] must be non-NIL.
  502.  */
  503.  
  504. #define    Proc_IsMigratedProcess() \
  505.     (proc_RunningProcesses[Mach_GetProcessorNumber()]->rpcClientProcess != \
  506.         ((Proc_ControlBlock *) NIL))
  507.  
  508. /*
  509.  * Used to get the lock at the top of the lock stack without popping it off.
  510.  */
  511. #define Proc_GetCurrentLock(pcbPtr, typePtr, lockPtrPtr) \
  512.     { \
  513.     if ((pcbPtr)->lockStackSize <= 0) { \
  514.         *(typePtr) = -1; \
  515.         *(lockPtrPtr) = (Address) NIL; \
  516.     } else { \
  517.         *(typePtr) = (pcbPtr)->lockStack[(pcbPtr)->lockStackSize-1].type; \
  518.         *(lockPtrPtr) = \
  519.         (pcbPtr)->lockStack[(pcbPtr)->lockStackSize-1].lockPtr; \
  520.     } \
  521.     }
  522. /* 
  523.  * External procedures.
  524.  */
  525.  
  526. extern void              Proc_Init();
  527. extern void              Proc_InitMainProc();
  528. extern ReturnStatus        Proc_NewProc();
  529. extern void            ProcStartUserProc();
  530. extern void            Proc_ExitInt();
  531. extern void            Proc_Exit();
  532. extern void            Proc_DetachInt();
  533. extern ReturnStatus        Proc_Detach();
  534. extern void            Proc_InformParent();    
  535. extern void            Proc_Reaper();
  536. extern void            Proc_NotifyMigratedWaiters();
  537. extern void            Proc_PutOnDebugList();
  538. extern void            Proc_SuspendProcess();
  539. extern void            Proc_ResumeProcess();
  540. extern int            Proc_ExecEnv();
  541. extern ReturnStatus         Proc_GetHostIDs();
  542.  
  543.  
  544. extern ReturnStatus        Proc_EvictForeignProcs();
  545. extern ReturnStatus        Proc_EvictProc();
  546. extern Boolean            Proc_IsMigratedProc();
  547. extern void            Proc_FlagMigration();
  548. extern void            Proc_MigrateTrap();
  549. extern void            Proc_OkayToMigrate();
  550. extern ReturnStatus        Proc_MigSendUserInfo();
  551. extern ReturnStatus        Proc_DoRemoteCall();
  552. extern void            Proc_SetEffectiveProc();
  553. extern Proc_ControlBlock *    Proc_GetEffectiveProc();
  554. extern ReturnStatus        Proc_ByteCopy();
  555. extern ReturnStatus        Proc_MakeStringAccessible();
  556. extern void            Proc_MakeUnaccessible();
  557. extern void            Proc_MigrateStartTracing();
  558. extern void            Proc_DestroyMigratedProc();
  559. extern void            Proc_NeverMigrate();
  560.  
  561. extern void            ProcInitMainEnviron();
  562. extern void            ProcSetupEnviron();
  563. extern void            ProcDecEnvironRefCount();
  564.  
  565. extern void            Proc_SetServerPriority();
  566.  
  567. extern    int            Proc_KillAllProcesses();
  568. extern    void            Proc_WakeupAllProcesses();
  569.  
  570. extern    void            Proc_Unlock();
  571. extern    void            Proc_Lock();
  572. extern    Proc_ControlBlock    *Proc_LockPID();
  573. extern    ReturnStatus        Proc_LockFamily();
  574. extern    void            Proc_UnlockFamily();
  575. extern    void            Proc_TakeOffDebugList();
  576. extern    Boolean            Proc_HasPermission();
  577.  
  578. extern    void            Proc_ServerInit();
  579. extern    void            Proc_CallFunc();
  580. extern    ClientData        Proc_CallFuncAbsTime();
  581. extern    void            Proc_ServerProc();
  582. extern    int            proc_NumServers;
  583.  
  584. extern  ReturnStatus        Proc_Dump();
  585. extern  ReturnStatus        Proc_DumpPCB();
  586.  
  587. extern  void            Proc_RemoveFromLockStack();
  588. extern  void            Proc_PushLockStack();
  589.  
  590. /*
  591.  * The following are kernel stubs corresponding to system calls.  They
  592.  * used to be known by the same name as the system call, but the C library
  593.  * has replaced them at user level in order to use the stack environments.
  594.  * The "Stub" suffix therefore avoids naming conflicts with the library.
  595.  */
  596.  
  597. extern ReturnStatus        Proc_SetEnvironStub();
  598. extern ReturnStatus        Proc_UnsetEnvironStub();
  599. extern ReturnStatus        Proc_GetEnvironVarStub();
  600. extern ReturnStatus        Proc_GetEnvironRangeStub();
  601. extern ReturnStatus        Proc_InstallEnvironStub();
  602. extern ReturnStatus        Proc_CopyEnvironStub();
  603. extern int                      Proc_KernExec();
  604.  
  605. #endif /* _PROC */
  606.